﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class MainForm : DevComponents.DotNetBar.Office2007RibbonForm
    {
        
        public MainForm()
        {
            InitializeComponent();
            DocThamso();
            StaticVariables.SetDefault();
            ModifyControls();                                                                   
        }
        private void DocThamso(){
            ThamSoDTO thamso = ThamSoBUS.TimThamSo();
            StaticVariables.TuoiToiDa = thamso.TuoiToiDa;
            StaticVariables.TuoiToiTieu = thamso.TuoiToiThieu;
            StaticVariables.ThoiHanThe = thamso.ThoiHanThe;
            StaticVariables.KhoangCachNamXB = thamso.KhoangCachNamXB;
            StaticVariables.SoLuongMuonToiDa = thamso.SoLuongMuonToiDa;
            StaticVariables.ThoiGianMuonToiDa = thamso.ThoiGianMuonToiDa;
            StaticVariables.TienPhat = thamso.TienPhat;
        }
        public static void GetUserData(DataTable user){
            DataRow dr = user.Rows[0];
            try
            {
                StaticVariables.UserID = dr["UserID"].ToString();
                StaticVariables.UserPw = dr["UserPassword"].ToString();
                StaticVariables.UserRole = dr["VaiTro"].ToString();
                StaticVariables.UserAuthorizationID = int.Parse(dr["Quyen"].ToString());
                StaticVariables.UserAuthorizationString = dr["Description"].ToString();
                StaticVariables.UserPriority = int.Parse(dr["Priority"].ToString());
            }
            catch (Exception ex)
            {
            }
            StaticVariables.SetViaAuthorization();
        }

        public void ModifyControls()
        {
            ribbonBar1.Enabled = StaticVariables.QuanlyEnable;
            ribbonBar3.Enabled = StaticVariables.QuanlyEnable;
            ribbonBar4.Enabled = StaticVariables.QuanlyEnable;
            ribbonBar5.Enabled = StaticVariables.QuanlyEnable;
            ribbonBar6.Enabled = StaticVariables.QuanlyEnable;
            ribbonBar7.Enabled = StaticVariables.QuanlyEnable;
            ribbonBar2.Enabled = StaticVariables.TratreEnable;
            ribbonBar8.Enabled = StaticVariables.LuotmuonEnable;
            rbUserAdmin.Enabled = StaticVariables.UserControlEnable;
            rbbOtherUser.Enabled = StaticVariables.UserManagement;
            btiLogin.Enabled = !btiLogin.Enabled;
            btiLogout.Enabled = !btiLogout.Enabled;
        }
        //Ham thiet ke phu tro
        private void ClearPanel()
        {
            panelMain.Controls.Clear();
        }         
        public void GetValue(String str)
        {
            txtBox_ThongBao.Text = str;
        }

        //---------------------------------------------------------
        private void btnQuanLySach_Click(object sender, EventArgs e)
        {
            ClearPanel();
            CuonSach cuonsach = new CuonSach();
            panelMain.Controls.Add(cuonsach);
            cuonsach.MyGetData = new CuonSach.GetString(GetValue);   
        }

        private void btnLoaiSach_Click(object sender, EventArgs e)
        {
            ClearPanel();
            LoaiSach loaiSach = new LoaiSach();
            panelMain.Controls.Add(loaiSach);
            loaiSach.MyGetData = new LoaiSach.GetString(GetValue);
        }

        private void btnTuaDeSach_Click(object sender, EventArgs e)
        {
            ClearPanel();
            TuaDeSach _tuaDeSach = new TuaDeSach();
            panelMain.Controls.Add(_tuaDeSach);
            _tuaDeSach.MyGetData = new TuaDeSach.GetString(GetValue);
        }

        private void buttonItem15_Click(object sender, EventArgs e)
        {
            ClearPanel();
            LanXB _lanXb = new LanXB();
            panelMain.Controls.Add(_lanXb);
            _lanXb.MyGetData = new LanXB.GetString(GetValue);
        }

        private void btnBaoTC_Click(object sender, EventArgs e)
        {
            ClearPanel();
            BaoTapChi _baoTapChi = new BaoTapChi();
            panelMain.Controls.Add(_baoTapChi);
            _baoTapChi.MyGetData = new BaoTapChi.GetString(GetValue);
        }

        private void btnKyXB1_Click(object sender, EventArgs e)
        {
            ClearPanel();
            KyXB kyXB = new KyXB();
            panelMain.Controls.Add(kyXB);
            kyXB.MyGetData = new KyXB.GetString(GetValue);
        }

        private void btnNhaXB1_Click(object sender, EventArgs e)
        {
            ClearPanel();
            NhaXB _nhaXB = new NhaXB();
            panelMain.Controls.Add(_nhaXB);
            _nhaXB.MyGetData = new NhaXB.GetString(GetValue);
        }

        private void tbnQuanLyDocGia_Click(object sender, EventArgs e)
        {
            ClearPanel();
            DocGia docGia = new DocGia();
            panelMain.Controls.Add(docGia);
            docGia.MyGetData = new DocGia.GetString(GetValue);
        }

        private void btnQuanLyMuonSach_Click(object sender, EventArgs e)
        {
            ClearPanel();
            PhieuMuonSach phieuMuonSach = new PhieuMuonSach();
            panelMain.Controls.Add(phieuMuonSach);
            phieuMuonSach.MyGetData = new PhieuMuonSach.GetString(GetValue);

        }

        private void buttonItem18_Click(object sender, EventArgs e)
        {
            ClearPanel();
            PhieuTraSach _phieuTra = new PhieuTraSach();
            panelMain.Controls.Add(_phieuTra);
            //_phieuTra.MyGetData = new PhieuTraSach.GetString(GetValue);
        }

        private void btnThuTien_Click(object sender, EventArgs e)
        {
            ClearPanel();
            PhieuThuTien phieuThu = new PhieuThuTien();
            panelMain.Controls.Add(phieuThu);
            phieuThu.MyGetData = new PhieuThuTien.GetString(GetValue);
        }

        private void btnTacGia1_Click(object sender, EventArgs e)
        {
            ClearPanel();
            TacGia _tacGia = new TacGia();
            panelMain.Controls.Add(_tacGia);
            _tacGia.MyGetData = new TacGia.GetString(GetValue);
        }

        private void btnChiTietTDTG_Click(object sender, EventArgs e)
        {
            ClearPanel();
            ChiTietTuaDeTacGia _chiTiet = new ChiTietTuaDeTacGia();
            panelMain.Controls.Add(_chiTiet);
            _chiTiet.MyGetData = new ChiTietTuaDeTacGia.GetString(GetValue);
        }

        private void buttonItem13_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSachTre_Click(object sender, EventArgs e)
        {
            ClearPanel();
            ThongKeSachTraTre thongke= new ThongKeSachTraTre();
            panelMain.Controls.Add(thongke);
        }

        private void btnThongKeLuotMuon_Click(object sender, EventArgs e)
        {
            ClearPanel();
            BaoCaoLuotMuonTrogThang baocao= new BaoCaoLuotMuonTrogThang();
            panelMain.Controls.Add(baocao);
        }
        private void btiLogin_Click(object sender, EventArgs e)
        {
            login();
        }

        private void login()
        {

            LoginForm loginfrm = new LoginForm(this);
            loginfrm.Show();
        }

        private void rbtSearch_Click(object sender, EventArgs e)
        {
            ClearPanel();
            panelMain.Controls.Add(new TraCuu());
        }

        private void rbtRules_Click(object sender, EventArgs e)
        {
            ClearPanel();
            panelMain.Controls.Add(new Rules());
        }

        private void rbtManagement_Click(object sender, EventArgs e)
        {
            ClearPanel();
        }

        private void rbtiStatistic_Click(object sender, EventArgs e)
        {

            ClearPanel();
        }

        private void rbtUser_Click(object sender, EventArgs e)
        {

            ClearPanel();
        }

        private void rbtiHelp_Click(object sender, EventArgs e)
        {

            ClearPanel();
        }

        private void btiLogout_Click(object sender, EventArgs e)
        {
            logout();
        }

        private void logout()
        {

            DialogResult dr = MessageBox.Show("Bạn có muốn đăng xuất?", "Nhắc nhở", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (dr == DialogResult.No)
                return;
            StaticVariables.SetDefault();
            ModifyControls();
            ClearPanel();
        }

        private void btnUseredit_Click(object sender, EventArgs e)
        {
            ClearPanel();
            panelMain.Controls.Add(new UserControlPanel());
        }

        private void btiOtherUser_Click(object sender, EventArgs e)
        {
            ClearPanel();
            panelMain.Controls.Add(new Quanlyuserduoiquyen());
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            login();
        }

        private void AboutButton_Click(object sender, EventArgs e)
        {
            AboutForm aboutfrm = new AboutForm();
            aboutfrm.Show();
        }

        //private void MainForm_KeyDown(object sender, KeyEventArgs e)
        //{
            
        //}

        //private void ribQuanLySach_KeyDown(object sender, KeyEventArgs e)
        //{
        //    if (e.Control && e.KeyCode == Keys.L)
        //    {
        //        login();
        //    }
        //    if (e.Control && e.Shift && e.KeyCode == Keys.L)
        //    {
        //        logout();
        //    }
        //}

        //private void ribQuanLySach_KeyUp(object sender, KeyEventArgs e)
        //{
        //    if (e.Control && e.KeyCode == Keys.L)
        //    {
        //        login();
        //    }
        //    if (e.Control && e.Shift && e.KeyCode == Keys.L)
        //    {
        //        logout();
        //    }
        //}

        

       
    }
}
